package com.yulongtian.oneProblemEveryDay.month202301;

/**
 * https://leetcode.cn/problems/check-if-matrix-is-x-matrix/
 *
 * @author yulongTian
 * @create 2023-01-31 13:26
 */
public class Test22 {
    public static void main(String[] args) {

    }

    public static boolean checkXMatrix(int[][] grid) {
        boolean flag1 = true;
        boolean flag2 = true;

        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[i].length; j++) {
                //对角线
                if (i == j || i + j == grid.length - 1) {
                    if (flag1) {
                        if (grid[i][j] == 0) {
                            flag1 = false;
                        }
                    }
                } else {
                    //非对角线
                    if (flag2) {
                        if (grid[i][j] != 0) {
                            flag2 = false;
                        }
                    }
                }

                if (!flag1 || !flag2) {
                    return false;
                }
            }
        }
        return true;
    }
}
